package com.chocho.producerserver.dao;

import com.chocho.producerserver.bean.QCollection;
import com.chocho.producerserver.bean.Test;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * Created by chocho on 2022/4/12.
 */
@Mapper
@Repository
public interface TestDao {
    @Insert("INSERT INTO op_test (test_id, test_output, question_id, test_input, test_name, test_score, test_note, test_status) " +
            "VALUES(#{testId}, #{testOutput}, #{questionId}, #{testInput}, #{testName}, #{testScore}, #{testNote}, #{testStatus})")
    int insert(Test test);

    @Select("<script>" +
            "SELECT * FROM op_test " +
            "<where>" +
            "<trim suffixOverrides='and'> " +
            "<if test=\"testStatus != \'\' and testStatus != null\"> test_status like CONCAT('%',#{testStatus},'%')</if> " +
            "</trim> " +
            "<trim suffixOverrides='and'> " +
            "<if test=\"testId != \'\' and testId != null\"> test_id like CONCAT('%',#{testId},'%')</if> " +
            "</trim> " +
            "<trim suffixOverrides='and'> " +
            "<if test=\"questionId != \'\' and questionId != null\"> question_id like CONCAT('%',#{questionId},'%')</if> " +
            "</trim> " +
            "<trim suffixOverrides='and'> " +
            "<if test=\"testName != \'\' and testName != null\"> test_name like CONCAT('%',#{testName},'%')</if> " +
            "</trim> " +
            "</where>" +
            "</script>")
    List<Test> getTestByQuery(Map<String, Object> map);

    @Delete("<script>" +
            "DELETE FROM op_test WHERE test_id in " +
            "<foreach collection=\"list\" open=\"(\" close=\")\" separator=\",\"  item=\"item\"> #{item}" +
            "</foreach>" +
            "</script>")
    int delete(List<String> idList);

    @Update("UPDATE op_test " +
            "SET test_output = #{testOutput}, test_input = #{testInput}, test_name = #{testName}, test_score = #{testScore}, test_note = #{testNote}, test_status=#{testStatus} " +
            "WHERE test_id = #{testId}")
    int update(Test test);

    @Select("<script>" +
            "SELECT * FROM op_test WHERE test_id in " +
            "<foreach collection=\"list\" open=\"(\" close=\")\" separator=\",\"  item=\"item\"> #{item}" +
            "</foreach>" +
            "</script>")
    List<Test> getByIdList(List<String> idList);
}
